import random

import pygame


class FoodSprite(pygame.sprite.Sprite):
    def __init__(self, left, top):
        super().__init__()
        self.image = pygame.surface.Surface((60, 60))
        pygame.draw.circle(self.image, (0, 125, 0), (30, 30), 30)
        self.rect = self.image.get_rect()
        self.rect.left = left
        self.rect.top = top


class FoodManage:
    def __init__(self, gm):
        self.food_group = pygame.sprite.Group()

        self.generate()
        self.gm = gm

    def generate(self):
        left = random.randint(0, 740)
        top = random.randint(0, 540)
        self.food1 = FoodSprite(left, top)
        self.food1.add(self.food_group)

    def update(self):
        if self.gm.state == "gaming":
            self.food_group.draw(self.gm.screen)
            self.food_group.update()

